__doc__ =   """ Contains holders of entities. Holders of entities are
                temporary and are outside the parent-children axes.
            """

from MultiEntity import MultiEntity
from numpy import mean

class Holder(MultiEntity):

    def __init__(self, name, *args):
        if not hasattr(self, 'level'):
            self.level = name
        MultiEntity.__init__(self, name, name, *args)

    def __repr__(self):
        return '<Holder id=%s>' % self.get_id()

    def add_child(self, child):
        """ Add a child to the Holder.
        """
        child_id = child.get_full_id()
        self[child_id] = child

    def del_child(self, child_id):
        """ Remove a child from Holder.
        """
        self.pop(child_id)

    def update_ids(self):
        ids = []
        for (id_, child) in self.iteritems():
            new_id = child.get_full_id()
            if id_ != new_id:
                ids.append((id_, new_id))
        for (old_id, new_id)  in ids:
            child = self.pop(old_id)
            self.update(((new_id, child),))


class ChainHolder(Holder):

    def __init__(self, *args):
        self.level = 'M'
        Holder.__init__(self, *args)

    def __repr__(self):
        return "<ChainHolder id=%s>" % self.get_id()


class ResidueHolder(Holder):

    def __init__(self, *args):
        self.level = 'C'
        Holder.__init__(self, *args)

    def __repr__(self):
        return "<ResidueHolder id=%s>" % self.get_id()


class AtomHolder(Holder):

    def __init__(self, *args):
        self.level = 'R'
        Holder.__init__(self, *args)

    def __repr__(self):
        return "<AtomHolder id=%s>" % self.get_id()

#EOF

